package com.ceba.test.base.language.resources;


import com.ceba.test.base.configs.CebaConfig;
import com.ceba.test.base.constants.CustomStampConstants;
import com.ceba.test.base.web.UserUtils;
import org.apache.commons.lang.StringUtils;

import com.ceba.test.base.configs.CebaPathUtil;
import com.ceba.test.base.helper.SystemHelper;
import com.ceba.test.base.language.ResourceUtils;

import configs.context.ResourceContext;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;


public class WebMessages {

	/**
	 * 网页上获取国际化信息
	 * @param resourceName
	 * @return
	 */
	public static String getWebMessage(String resourceName){
		return ResourceUtils.getMessage(resourceName);
	}
	
	/**
	 * 取得项目访问路径
	 * @return
	 */
	public static String getContextPath(){
		return CebaPathUtil.getProjectContextPath();
	}
	
	/**
	 * jsp文件父目录名称
	 */
	public static String getJSPDirName(){
		return CebaPathUtil.getJSPDirName();
	}
	/**
	 * 取得文件总路径
	 * @return
	 */
//	public static String getPhysicalWebUploadPath(){
//		return CebaPathUti.getPhysicalWebUploadPath();
//	}
	
	
	/**
	 * 取得国家标识
	 * @return  zh-CN
	 */
	public static String getLanguage(){
		return ResourceContext.getMessageLocal().toString().replace("_", "-");
	}

	/**
	 * 软件和系列名称
	 * DS-SE
	 * @return
	 */
	public static String getCompleteProductName(){
		return  SystemHelper.getCompleteProductName();
	}
	
	/**
	 * 取得语言标识
	 * @return zh_CN
	 */
	public static String getLanguage(String flag){
		String language=null;
		language= getLanguage();
		if(StringUtils.equals(flag, "underline")){
			return language;//zh_CN
		}else if(StringUtils.equals(flag, "lowercase")){
			return language.toLowerCase();//zh_cn
		}else if(StringUtils.equals(flag, "crossBar")){
			return language.replace("_", "-");//zh-CN
		}else if(StringUtils.equals(flag, "crossBarLowercase")){
			return language.replace("_", "-").toLowerCase();//zh-cn
		}else if(StringUtils.equals(flag, "bottomLine")){
			return language.replace("-","_");
		}
		return language;
	}
	
	/**
	 * 获取系统简写名称--无版本号
	 * @return
	 */
	public static String getSystemName(){
		return SystemHelper.getSystemName();
	}
	
	/*
	 * 系统全称--有大版本号
	 */
	public static String getSystemBigVersion(){
		return SystemHelper.getSystemBigVersion();
	}
	
	/*
	 * 系统全称--完整版本号
	 */
	public static String getSystemCompleteVersion(){
		return SystemHelper.getSystemCompleteVersion();
	}
	
	/*
	 * 系统版本
	 */
	public static String getSystemSimpleVersion(){
		return SystemHelper.getSystemSimpleVersion();
	} 
	
	/**
	 * 当前系统登录用户
	 * @return
	 */
	public static String getSystemNowUserName(HttpServletRequest request){
		return UserUtils.getUserName(request);
		//return "";
	}
	
	/**
	 * 取得系统参数配置
	 * @param name
	 * @return
	 */
	public static String getConfig(String name){
		if("PATTER_LOGO_FLAG".equals(name)){
			return CebaConfig.PATTER_LOGO_FLAG;
		}else if("LOGIN_TYPE".equals(name)){
			return CebaConfig.LOGIN_TYPE;
		}else if("AD_SERVER_NET_URL".equals(name)){
			return CebaConfig.AD_SERVER_NET_URL;
		}else if("PDF_CREATE_MODE".equals(name)){
			return CebaConfig.PDF_CREATE_MODE;
		}else if("MERGE_MAX_COUNT".equals(name)){
			return CebaConfig.MERGE_MAX_COUNT;
		}else if("AUTOMATIC_SIGNATURE_FLAG".equals(name)){
			return CebaConfig.AUTOMATIC_SIGNATURE_FLAG;
		}else if("HIDDEN_EMAIL_FLAG".equals(name)){
			return CebaConfig.HIDDEN_EMAIL_FLAG;
		}else if("MESSAGE_CONFIG".equals(name)){
			try {
				return  URLEncoder.encode(ResourceUtils.getMessageConfig(), "utf-8");
			} catch (UnsupportedEncodingException e) {
				//logger.debug(e.getMessage());
				e.printStackTrace();
			}
		}else if("KEY_MULTI_LABLE_FLAG".equals(name)){
			return CebaConfig.KEY_MULTI_LABLE_FLAG;
		}
		return null;
	}


	/**
	 * //前端数字签名不需要签名时传的标识
	 * @return
	 */
	public static String getNoSignString(){
		return CustomStampConstants.NO_SIGN;
	}
	/**
	 * 獲取系統收費類型
	 * @return
	 */
	public static String getSystemFeeType(){
		return SystemHelper.getSystemFeeType();
	}
	
	/**
	 * 系统到期时间
	 * @return
	 */
	public static String getEndUseTime(){
		return SystemHelper.getEndUseTime();
	}
	
	/**
	 * 获取系统是否激活
	 * @return
	 */
	public static String getSignCompanyActiveFlag(){
		return SystemHelper.getSignCompanyActiveFlag();
	}
	/**
	 * 是否可以服务签名
	 */
	public static String getCanServerSign(){
		return SystemHelper.canChooseServerSignFlow()?"true":"false";
	}
	
	/**
	 * 系统系列版本
	 */
	public static String getUserVision(){
		return SystemHelper.getUserVision();
	}
	
	/**
	 * 系统版本号3.5.0
	 */
	public static String getVersion(){
		return SystemHelper.getVersion();
	}
	/**
	 * 系统注册名称
	 */
	public static String getEnterpriseRegisterName(){
		return SystemHelper.getEnterpriseRegisterName();
	}


}
